package com.example.rentingapp.activity;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.example.rentingapp.R;
import com.example.rentingapp.fragment.Successful_Order_Fragment;
import com.example.rentingapp.fragment.Tenant_Order_Fragment;
import com.example.rentingapp.fragment.Wait_Order_Fragment;
import com.example.rentingapp.fragment.Landlord_Order_Fragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class MyOrderActivity extends BaseActivity implements View.OnClickListener {
    private ImageView iv_Back;
    static final int NUM_ITEMS = 4;
    private List<Fragment> fragmentList = new ArrayList<Fragment>();
    private String[] strings = new String[]{"房东订单","房客订单","已完成订单","待确认订单"};

    @Override
    protected int initLayout() {
        return R.layout.activity_my_order;
    }

    @Override
    protected void initView() {
        iv_Back = findViewById(R.id.iv_back);
        TabLayout tab_layout = findViewById(R.id.tab_layout);
        ViewPager viewPager = findViewById(R.id.viewPager);
        MyAdapter fragmentAdater = new  MyAdapter(getSupportFragmentManager());
        viewPager.setAdapter(fragmentAdater);
        tab_layout.setupWithViewPager(viewPager);
    }

    @Override
    protected void initData() {
        fragmentList.add(new Landlord_Order_Fragment());
        fragmentList.add(new Tenant_Order_Fragment());
        fragmentList.add(new Successful_Order_Fragment());
        fragmentList.add(new Wait_Order_Fragment());
        iv_Back.setOnClickListener(this);//返回按钮
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }


    //查找订单
    private void findOrderByUserId() {
        String userId = findByKey("user_id");
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("orders_landlord_id", userId);
        params.put("orders_tenant_id", userId);

    }

    public class MyAdapter extends FragmentPagerAdapter {
        public MyAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return NUM_ITEMS;
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return strings[position];
        }
    }


}